import { defineStore } from "pinia";
import {getVideoPage} from "@/api/api";

const useVideoInfoStore = defineStore('videoInfo',{
    state:() => ({
        categories:{
            // // 动画等等....
            // home:[],
            // // 其他频道视频
            // other:[],
        },
        config:{
            pageSize: 10,
            // 最大视频数
            maxSize: 100,
            // 容器滚动位置
            scrollTop:0,

            // 还维护所有可以滑动的视频界面的pageNum，例如
        }
    }),

    getters:{

        isFull() {
            if (this.categories.home === undefined) this.categories.home = [];
            return this.categories.home.length >= this.config.maxSize;
        }

    },

    actions:{
        // 获取home视频页
        async getHomeVideoPage(pageNum){
            if(this.categories.home === undefined) this.categories.home = [];
            const data = await getVideoPage(pageNum, this.config.pageSize)
            console.log(data)
            if(data !== null) {
                this.categories.home.push(...data.list);
                return true;
            }else{
                console.log(123)
                return false;
            }
        },


        // 设置滚动为0
        setScrollZero(){
            this.config.scrollTop = 0;
        }


    }
})

export default useVideoInfoStore